#pragma once
#include "api.h"
#include "game.h"
#include "lua-worker.h"
#include "utils.h"
#include <Windows.h>
#include <memory>

struct Mgr : public Singleton<Mgr> {
  void create_pool(int num);
  void destroy_pool();
  void suspend_pool();
  void resume_pool();
  void run_worker(const std::string &file_path,
                  const std::string &file_root_path,
                  const std::string &script = "");
  void stop_all_scripts();
  std::shared_ptr<Api> api() const;
  std::shared_ptr<Game> game() const;
  uint64 base() const;
  HWND window() const;
  uint32 pid() const;
  void init(uint32 pid, HWND window, uint64 base);
  // --- Constructors ---
  Mgr(Mgr &&) = delete;
  Mgr(const Mgr &) = delete;
  Mgr &operator=(Mgr &&) = delete;
  Mgr &operator=(const Mgr &) = delete;
  ~Mgr();

  LuaWorker *worker_{nullptr};

private:
  uint32 pid_{0};
  HWND window_{NULL};
  uint64 base_{0};
  std::shared_ptr<Game> game_{nullptr};
  std::shared_ptr<Api> api_{nullptr};
  WorkQueue work_queue_;
  uint32 threads_num_;
  friend Singleton<Mgr>;
  Mgr();
};

inline auto game() { return Mgr::get()->game(); }

inline auto api() { return Mgr::get()->api(); }
